'use strict'

import HybridJS from '../core/core'

const $ = HybridJS

/**
 * 设置悬浮框 {  img:”url”,          //图片链接
 *              href:”url”,         //点击跳转url
 *              width:100,          //悬浮框宽度
 *              height:100,         //悬浮框高度
 *              margin:{left:0,top:0,right:0,bottom:0}, //悬浮框相对于父view的margin，默认0，0，0，0
 *              alphaNormal:1,      //正常情况下透明度，默认为1
 *              alphaDrag:1,        //拖拽时透明度，默认为1
 *              dragEnable:true,    //是否可拖拽，默认为true
 *              adsorbEnable:true   //是否自动吸附边缘，默认为true
 *            }
 */
function setFloatView (obj) {
    return $.callNativeSync("page","setFloatView",obj)
}

/**
 * 显示悬浮框
 * @returns {*}
 */
function showFloatView() {
    return $.callNativeSync("page","showFloatView")
}

/**
 * 隐藏悬浮框
 * @returns {*}
 */
function hideFloatView() {
    return $.callNativeSync("page","hideFloatView")
}

/**
 * 显示loading
 * @param obj 配置参数
 * @returns {*}
 */
function showLoading(obj) {
    return $.callNativeSync("page","showLoading",obj)
}

/**
 * 隐藏loading
 * @returns {*}
 */
function hideLoading() {
    return $.callNativeSync("page","hideLoading")
}

/**
 * 监听页面可见
 * @param {*} callback 
 */
function onPageDidAppear(callback) {
    return $.onListenEvent("onPageDidAppear", callback)
}

/**
 * 监听页面不可见
 * @param {*} callback 
 */
function onPageDidDisappear(callback) {
    return $.onListenEvent("onPageDidDisappear", callback)
}
export default {
    setFloatView,
    showFloatView,
    hideFloatView,
    showLoading,
    hideLoading,
    onPageDidAppear,
    onPageDidDisappear
}